Competitive Programming

Greedy Algorithms Explained

Si Yuan20 Oct 2024

Definitions

Greedy algorithms make the locally optimal choice at each stage with the hope of finding a global optimum. Here's how they work:

Principles

  • Local Optimality: At each step, choose the option that seems best at the moment.
  • Feasibility: Ensure the choice is still feasible and does not violate any constraints.

Common Problems

  1. Activity Selection: Choose the maximum number of compatible activities.
  2. Huffman Coding: Build a binary tree to optimize data encoding.

Greedy algorithms are efficient and can be applied to a variety of problems, but they don't always guarantee the best solution.